package com.subsequent.controller;

import com.subsequent.pojo.Respond;
import com.subsequent.service.RespondService;
import com.subsequent.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/respond")
public class RespondController {
    @Resource
    private RespondService respondService;


    @GetMapping("/findAll")
    public Result findAll(){
        List<Respond> respondsList = respondService.list();
        if(respondsList!=null){
            return Result.success(respondsList);
        }
        return Result.error("查询失败");
    }
    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        boolean b = respondService.removeById(id);
        if(b){
            return Result.success();
        }else {
            return Result.error("删除失败");
        }
    }
    @PostMapping("/AddContent")
    public Result AddContent(@RequestBody Respond respond){
        boolean save = respondService.save(respond);
        if(save){
            return Result.success();
        }else {
            return Result.error("添加失败");
        }
    }
    @PostMapping("/updateContent")
    public Result updateContent(@RequestBody Respond respond){
        boolean b = respondService.updateById(respond);
        if(b){
            return Result.success();
        }else {
            return Result.error("修改失败");
        }
    }
}
